package com.project.controller;

import com.framework.core.result.APIObjResponse;
import com.framework.core.result.BasePage;
import com.project.biz.CmsBannerBiz;
import com.project.entity.CmsBanner;
import com.project.pojo.dto.CmsCapitalFlowDTO;
import com.project.pojo.model.GetCmsCapitalFlowModel;
import com.project.pojo.model.QueryBannerModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @description: banner管理
 * @author: longer
 * @create: 2020-12-18 17:54
 **/
@Api(value = "CmsBannerController", description = "banner管理")
@RestController
@RequestMapping("/banner")
@Slf4j
public class CmsBannerController {

    /**
     * banner管理业务层接口类
     */
    @Autowired
    private CmsBannerBiz bannerBiz;

    /**
     * 按条件查询banner
     * @return
     */
    @ApiOperation(value = "按条件查询banner", httpMethod = "POST")
    @PostMapping(value = "/getBannerList")
    public APIObjResponse<BasePage<CmsBanner>> getBannerList(@RequestBody QueryBannerModel queryBannerModel){
        BasePage<CmsBanner> basePage = this.bannerBiz.getBannerList(queryBannerModel);
        return APIObjResponse.success("查询成功", basePage);
    }

    /**
     * 增加banner
     * @return
     */
    @ApiOperation(value = "增加banner", httpMethod = "POST")
    @PostMapping(value = "/addBanner")
    public APIObjResponse<Integer> addBanner(@Validated @RequestBody CmsBanner banner){
        Integer result = this.bannerBiz.addBanner(banner);
        return APIObjResponse.success("操作成功", result);
    }

    /**
     * 删除banner
     * @return
     */
    @ApiOperation(value = "删除banner", httpMethod = "GET")
    @GetMapping(value = "/deleteBanner")
    public APIObjResponse<Integer> deleteBanner(@RequestParam Long bannerId){
        Integer result = this.bannerBiz.deleteBanner(bannerId);
        return APIObjResponse.success("操作成功", result);
    }

    /**
     * 修改banner
     * @return
     */
    @ApiOperation(value = "修改banner", httpMethod = "POST")
    @PostMapping(value = "/updateBanner")
    public APIObjResponse<Integer> updateBanner(@RequestBody CmsBanner banner){
        Integer result = this.bannerBiz.updateBanner(banner);
        return APIObjResponse.success("操作成功", result);
    }
}
